package com.whfc.fuum.service.impl;

import com.whfc.fuum.dao.AppProjectPlanMapper;
import com.whfc.fuum.entity.AppProjectPlan;
import com.whfc.fuum.service.AppProjectPlanService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * 项目方案管理Service实现类
 *
 * @author dzg
 * @since 2025-09-23
 */
@DubboService(interfaceClass = AppProjectPlanService.class, version = "1.0.0")
public class AppProjectPlanServiceImpl implements AppProjectPlanService {

    @Autowired
    private AppProjectPlanMapper appProjectPlanMapper;

    @Override
    public AppProjectPlan getById(Integer id) {
        return appProjectPlanMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<AppProjectPlan> list(Integer deptId, String planName) {
        return appProjectPlanMapper.selectList(deptId, planName);
    }

    @Override
    public boolean save(AppProjectPlan projectPlan) {
        projectPlan.setDelFlag(0);
        projectPlan.setCreateTime(new Date());
        projectPlan.setUpdateTime(new Date());
        return appProjectPlanMapper.insert(projectPlan) > 0;
    }

    @Override
    public boolean update(AppProjectPlan projectPlan) {
        projectPlan.setUpdateTime(new Date());
        return appProjectPlanMapper.updateByPrimaryKey(projectPlan) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        AppProjectPlan projectPlan = getById(id);
        if (projectPlan != null) {
            projectPlan.setDelFlag(1);
            projectPlan.setUpdateTime(new Date());
            return update(projectPlan);
        }
        return false;
    }

    @Override
    public boolean deleteBatch(List<Integer> ids) {
        // 先逻辑删除
        for (Integer id : ids) {
            delete(id);
        }
        // 物理删除可以在后续清理任务中处理
        return true;
    }
}